package nl.unimaas.micc.eventSnookerTest.math;
public class Vector3D
{
	public double x;
	public double y;
	public double z;

	public static Vector3D nullVector()
	{
		return new Vector3D(0, 0, 0);
	}

	public Vector3D(double x, double y, double z)
	{
		this.x = x;
		this.y = y;
		this.z = z;
	}

	public Vector3D(Vector3D vector3D)
	{
		this.x = vector3D.x;
		this.y = vector3D.y;
		this.z = vector3D.z;
	}

	public Vector3D add(Vector3D vector2)
	{
		return new Vector3D(this.x + vector2.x, this.y + vector2.y, this.z
				+ vector2.z);
	}

	public Vector3D subtract(Vector3D vector2)
	{
		return new Vector3D(this.x - vector2.x, this.y - vector2.y, this.z
				- vector2.z);
	}

	public Vector3D multiply(double scalar)
	{
		return new Vector3D(this.x * scalar, this.y * scalar, this.z * scalar);
	}

	public double getLength()
	{
		return Math.sqrt(x * x + y * y + z * z);
	}

	public double dotProduct(Vector3D vector2)
	{
		return (this.x * vector2.x + this.y * vector2.y + this.z * vector2.z);
	}

	public boolean isZero()
	{
		return (x == 0 && y == 0 && z == 0);
	}

	public String toString()
	{
		return "(" + x + "," + y + "," + z + ")";
	}

	public Vector3D unit()
	{
		if(this.getLength() == 0)
		{
			return nullVector(); // TODO is this good?
		}
		return this.multiply(1 / this.getLength());
	}

	public double angleTo(Vector3D v2)
	{
		return Math.atan2(v2.y, v2.x)-Math.atan2(this.y, this.x);
		//return Math.acos(this.dotProduct(v2) / (this.getLength() * v2.getLength()));
	}

	public Vector3D crossProduct(Vector3D v2)
	{
		return new Vector3D(this.y * v2.z - this.z * v2.y, this.z * v2.x
				- this.x * v2.z, this.x * v2.y - this.y * v2.x);
	}
}
